package com.gviiii.pprf.common;

import java.io.File;
import java.math.BigInteger;

public class RFUtils {

    public static byte intToByte16(String i) {
        byte s = (new BigInteger(i, 16)).byteValue();
        return s;
    }

    public static String ByteArrayToStr(byte[] byteArray, int nStart, int nEnd) {
        String strReturn = "";
        if (nEnd > byteArray.length && nStart > byteArray.length) {
            strReturn = "C0";
            return strReturn;
        } else {
            for(int i = nStart; i < nEnd; ++i) {
                strReturn = strReturn + Integer.toString((byteArray[i] & 255) + 256, 16).substring(1);
            }

            return strReturn;
        }
    }

    public static String Decode(String bytes) {
        StringBuffer sb = new StringBuffer();

        for(int i = 0; i + 4 <= bytes.length(); i += 4) {
            if (!bytes.substring(i, i + 4).equals("0000")) {
                int j = Integer.parseInt(bytes.substring(i, i + 4), 16);
                sb.append((char)j);
            }
        }

        return sb.toString();
    }

    public static String Encode(String s) {
        String str = "";

        for(int i = 0; i < s.length(); ++i) {
            int ch = s.charAt(i);
            String ds = Integer.toHexString(ch);
            if (ch > 128) {
                str = str + ds;
            } else {
                str = str + "00" + ds;
            }
        }

        return str.toUpperCase();
    }

    public static byte[] hexStringToByte(String hex) {
        String hexString = hex.trim();
        byte[] bytes = new byte[hexString.length() / 2];

        for(int i = 0; i < bytes.length; ++i) {
            bytes[i] = (byte)Integer.parseInt(hexString.substring(2 * i, 2 * i + 2), 16);
        }

        return bytes;
    }

    public static String times(String src, int n) {
        if (n < 1) {
            return "";
        } else {
            StringBuffer sb = new StringBuffer();
            --n;

            while(n > -1) {
                sb.append(src);
                --n;
            }

            return sb.toString();
        }
    }

    public static String getUrl() {
        String url = "";
        File f = new File(".");

        try {
            url = f.getCanonicalPath();
        } catch (Exception var3) {
            System.out.println("获取程序路径失败！！");
        }

        return url;
    }
}
